package admin.service.impl;

import admin.common.enums.UserErroeCodeEnum;
import admin.common.exception.ClientException;
import admin.dao.entity.UserDo;
import admin.dao.mapper.UserMapper;
import admin.dto.resp.UserRespDto;
import admin.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;

/**
 * 功能：
 * 作者：张赛特
 * 日期：2025/8/9 9:18
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDo> implements UserService  {
    @Override
    public UserRespDto getUserByUsername(String username) {
        LambdaQueryWrapper<UserDo> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(UserDo::getUsername,username);
        this.getOne(queryWrapper);
        UserDo userDo=baseMapper.selectOne(queryWrapper);
        if (userDo==null){
            throw new ClientException(UserErroeCodeEnum.USER_NULL);
        }
        UserRespDto respDto=new UserRespDto();
        BeanUtils.copyProperties(userDo,respDto);
        return respDto;
    }
}